import type { PropType } from 'vue';
import type { FormItemRule, FormRules, GridItemProps } from 'naive-ui';
export interface FormProps {
  size?: 'small' | 'medium' | 'large';
  labelWidth?: number;
  labelPlacement?: 'left' | 'top';
  inline?: boolean;
  rules?: FormRules;
  modelValue?: Record<string, any>;
  formItems?: FormItemProps[];
  formGrid?: GridItemProps;
  showSubmit?: boolean;
}

export type FormElementType =
  | 'input'
  | 'select'
  | 'checkbox'
  | 'radio'
  | 'date'
  | 'time'
  | 'number'
  | 'textarea'
  | 'switch';

export type FormEmits = ['submit'];

export interface FormItemProps {
  label: string;
  path: string;
  component: FormElementType;
  componentProps?: object;
  rules?: FormItemRule[];
  grid?: GridItemProps;
}

export const formItemProps = {
  label: {
    type: String,
    default: ''
  },
  path: {
    type: String,
    default: ''
  },
  component: {
    type: String,
    default: ''
  },
  componentProps: {
    type: Object,
    default: () => ({})
  },
  grid: {
    type: Object as PropType<GridItemProps>,
    default: () => ({})
  }
};

export const formProps = {
  size: {
    type: String as PropType<FormProps['size']>,
    default: 'medium'
  },
  labelWidth: {
    type: Number,
    default: 80
  },
  labelPlacement: {
    type: String as PropType<FormProps['labelPlacement']>,
    default: 'left'
  },
  inline: {
    type: Boolean,
    default: true
  },
  rules: {
    type: Object as PropType<FormRules>, // 数组类型用 PropType,
    default: () => ({})
  },
  modelValue: {
    type: Object as PropType<Record<string, any>>,
    default: () => ({})
  },
  formItems: {
    type: Array as PropType<FormItemProps[]>,
    default: () => []
  },
  formGrid: {
    type: Object as PropType<GridItemProps>,
    default: () => ({})
  }
};
